<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>五指山农污远程监控平台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/phoneLogin/admin.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/phoneLogin/login.css" media="all">

</head>
<body id="cas" >
<div id="container">
    <form id="fm1" action="<%=request.getContextPath()%>/rest/checkPhoneLogin" method="post" onsubmit="return check()">
        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>五指山农污处理系统及远程监控软件</h2>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                    <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
                            <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <img onclick="changeCode()" src="<%=request.getContextPath()%>/rest/getVerifyCode" class="layadmin-user-login-codeimg" id="LAY-user-get-vercode">
                            </div>
                        </div>
                    </div>
                </div>
                <!--  <div class="layui-form-item" style="margin-bottom: 20px;">
                    <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
                    <a href="forget.html" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？</a>
                  </div> -->
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
                </div>
                <!--  <div class="layui-trans layui-form-item layadmin-user-login-other">
                    <label>社交账号登入</label>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>

                    <a href="reg.html" class="layadmin-user-jump-change layadmin-link">注册帐号</a>
                  </div> -->
            </div>
        </div>

        <div class="layui-trans layadmin-user-login-footer">

            <p>@2021 <a>五指山水务有限公司</a></p>
<%--            <p>--%>
<%--                <span><a href="http://www.layui.com/admin/#get" target="_blank">获取授权</a></span>--%>
<%--                <span><a href="http://www.layui.com/admin/pro/" target="_blank">在线演示</a></span>--%>
<%--                <span><a href="http://www.layui.com/admin/" target="_blank">前往官网</a></span>--%>
<%--            </p>--%>
        </div>
    </form>

    <!--<div class="ladmin-user-login-theme">
      <script type="text/html" template>
        <ul>
          <li data-theme=""><img src="{{ layui.setter.base }}style/res/bg-none.jpg"></li>
          <li data-theme="#03152A" style="background-color: #03152A;"></li>
          <li data-theme="#2E241B" style="background-color: #2E241B;"></li>
          <li data-theme="#50314F" style="background-color: #50314F;"></li>
          <li data-theme="#344058" style="background-color: #344058;"></li>
          <li data-theme="#20222A" style="background-color: #20222A;"></li>
        </ul>
      </script>
    </div>-->

</div>
</div>
<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/lib/cas/js/cas.js"></script>
<link href="<%=request.getContextPath()%>/huazhi/login/jquery.confirm.css" rel="stylesheet">
<script src="<%=request.getContextPath()%>/huazhi/login/jquery-confirm.js"></script>
<script>

    function check() {
        var index =layui.layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        var username = $("#LAY-user-login-username").val();
        var password = $("#LAY-user-login-password").val();
        var  verifyCode = $("#LAY-user-login-vercode").val()
        if (username == "") {
            layui.layer.close(index)
            var usernames = document.getElementById("LAY-user-login-username");
            usernames.setAttribute("class", "layui-input layui-form-danger");
            usernames.focus();
            layui.layer.tips('请输入用户名', '#LAY-user-login-username', {
                tips: 2
            });
            return false;
        }
        if (password == "") {
            layui.layer.close(index)
            var passwords = document.getElementById("LAY-user-login-password");
            passwords.setAttribute("class", "layui-input layui-form-danger");
            passwords.focus();
            layui.layer.tips('请输入密码', '#LAY-user-login-password', {
                tips: 2
            });
            return false;
        }
        if(verifyCode == ""){
            layui.layer.close(index)
            var passwords = document.getElementById("LAY-user-login-vercode");
            passwords.setAttribute("class", "layui-input layui-form-danger");
            passwords.focus();
            layui.layer.tips('请输入验证码', '#LAY-user-login-vercode', {
                tips: 2
            });
            return false;
        }
        var flag = true;
        console.log(verifyCode)
        $.ajax({
            type: "post",
            url: "<%=request.getContextPath()%>/rest/getCheckByuserNamePasswordPhone",
            data: {
                username : username ,
                password : password,
                verifyCode: verifyCode
            } ,
            dataType: "json",
            async: false,
            success: function (data) {
                if(data.success == false){
                    layui.layer.close(index)
                    return false;
                }else{
                    if (data == "0") {
                        layui.layer.close(index)
                        layui.layer.tips('用户名错误', '#LAY-user-login-username', {
                            tips: 2
                        });
                        flag = false;
                        return false;
                    } else if (data == "1") {
                        layui.layer.close(index)
                        layui.layer.tips('用户已被禁用', '#LAY-user-login-username', {
                            tips: 2
                        });
                        flag = false;
                        return false;
                    }  else if (data == "2") {
                        layui.layer.close(index)
                        layui.layer.tips('密码错误', '#LAY-user-login-password', {
                            tips: 2
                        });
                        flag = false;
                        return false;
                    }else if(data == "4"){
                        layui.layer.close(index)
                        layui.layer.tips("验证码错误",'#LAY-user-login-vercode',{
                          tips:2
                        })
                        document.getElementById("LAY-user-get-vercode").src="<%=request.getContextPath()%>/rest/getVerifyCode?"+Math.random();
                        document.getElementById("LAY-user-login-vercode").value = ''
                        flag = false;
                        return false;
                    }
                    else {
                        layui.layer.close(index)
                        flag = true;
                        return false;
                    }
                }

            },
        })
        if (flag) {
            return true;
        } else {
            return false;
        }
    }
    function changeCode(){
        document.getElementById("LAY-user-get-vercode").src="<%=request.getContextPath()%>/rest/getVerifyCode?"+Math.random();
    }
</script>

</body>
</html>